Moving linksets script not working

Hi all,

 

I am working on a script to take all of the linksets in one link module and move them (along with their corresponding links) to another link module. The script seems to work flawlessly on some attempts, but loses links on others and does not return an error. I think the error could reside in cases where either the linkset already exists in the new link module, or when a linkset is linking a module to itself. However when I create these test cases it runs perfectly, only to run into errors again when I apply it to modules in a project. I would really appreciate if anyone could look over the script to see potential errors, or knows of a working script to dump the linksets from one link module into another.

 

The script is attached below.

View DetailsmovelinksetJohn'sUpdate.dxl

 

Thanks.


JohnEarnshaw - Wed Aug 05 11:32:54 EDT 2015

Re: Moving linksets script not working
llandale - Wed Aug 05 19:36:12 EDT 2015

So you are merging the links of two link modules into one of them.
I don't see a serious error.  I'm liking this code more and more as I read it.  I think you need to be more specific with which "errors" you are getting.
You are correctly staging links and linksets to be deleted, then deleting them after the relevant loop.
Is it possible you have full rights to the modules but not to their parent folders?  That would mess up your LMD stuff which can mess up your link-creates.

 

I'm a little worried when duplicating links when the target object is the same as the source object.  The link you create at line #114 becomes part of the loop at line #105.  That "should" not matter but it might.  You an put the Links from o1 into a skip list, then browse the Skip list; above line #105:

Skip skpLinks = create()
for l in o1 -> lmn do
{  put(skpLinks, I, I)

}

for l in skpLinks do    <-- current line #105

Line #103; not sure about "all", I always use "entire(m1)"; then continue if the object is deleted.

Line#168, loading the link set will open up both source/target modules; which I notice you leave open.  I do't think you need to load the linkset before deleting it.

Line #169 I notice you are not trapping the delete linkset attempt.

Line #81, surely you don't need a "flushDeletions" after removing the LMD?

Line #80, seems to me you should only attempt to remove and create the LMD if there currently exists one.

Line #100; yes creating a LinkSet when one already exists does't matter.
Line #41; I'd make sure that lmn != newLmName.

Line #70: add new elseif(!isEdit(m1)) then
Line #137: perhaps don't delete the links when dontDelete is true.

-Louie

 

Re: Moving linksets script not working
llandale - Wed Aug 05 19:37:14 EDT 2015

Is it possible you lack full rights to all the m1 objects?  Insert a "if (!canModify(o1))" at the top of the object loop.

Re: Moving linksets script not working
JohnEarnshaw - Thu Aug 06 13:54:07 EDT 2015

llandale - Wed Aug 05 19:36:12 EDT 2015

So you are merging the links of two link modules into one of them.
I don't see a serious error.  I'm liking this code more and more as I read it.  I think you need to be more specific with which "errors" you are getting.
You are correctly staging links and linksets to be deleted, then deleting them after the relevant loop.
Is it possible you have full rights to the modules but not to their parent folders?  That would mess up your LMD stuff which can mess up your link-creates.

 

I'm a little worried when duplicating links when the target object is the same as the source object.  The link you create at line #114 becomes part of the loop at line #105.  That "should" not matter but it might.  You an put the Links from o1 into a skip list, then browse the Skip list; above line #105:

Skip skpLinks = create()
for l in o1 -> lmn do
{  put(skpLinks, I, I)

}

for l in skpLinks do    <-- current line #105

Line #103; not sure about "all", I always use "entire(m1)"; then continue if the object is deleted.

Line#168, loading the link set will open up both source/target modules; which I notice you leave open.  I do't think you need to load the linkset before deleting it.

Line #169 I notice you are not trapping the delete linkset attempt.

Line #81, surely you don't need a "flushDeletions" after removing the LMD?

Line #80, seems to me you should only attempt to remove and create the LMD if there currently exists one.

Line #100; yes creating a LinkSet when one already exists does't matter.
Line #41; I'd make sure that lmn != newLmName.

Line #70: add new elseif(!isEdit(m1)) then
Line #137: perhaps don't delete the links when dontDelete is true.

-Louie

 

I really appreciate the feedback, you made some great points and I took it all into consideration while updating my script. I especially like the idea of flushing deletions after removing the LMD just in case there was an obscure overlap. However even with the new and improved script I still ran into the same error as before. The problem I am getting with the script is that before the merge I will use a script to count all the links in Link Module A, as well as all of the links in Link Module B. After running the script to put the links from link module B into A, I will count the links in link module A again. Here I am expecting the output to be the sum of the first two counts, however occasionally I get a result which is slightly less than the desired sum. When I have been able to trace this error down to a specific case, it was because some of the linksets in the new link module were empty and had moved over nothing at all, with no error message from my script. I just ran the script to move 6825 links into a LM with 4667 and got 11489 instead of 11492. I think that means an error in the script still exists, however maybe it is due to an odd anomaly of initially having the same link existing in both link modules. Let me know what you think, I have attached both the update script as well as the script I use to count the links in a Link Module.


Attachments

Count links in LM (not detailed).dxl
movelinksetJohn'sUpdate.dxl

Re: Moving linksets script not working
Mathias Mamsch - Fri Aug 07 11:10:21 EDT 2015

JohnEarnshaw - Thu Aug 06 13:54:07 EDT 2015

I really appreciate the feedback, you made some great points and I took it all into consideration while updating my script. I especially like the idea of flushing deletions after removing the LMD just in case there was an obscure overlap. However even with the new and improved script I still ran into the same error as before. The problem I am getting with the script is that before the merge I will use a script to count all the links in Link Module A, as well as all of the links in Link Module B. After running the script to put the links from link module B into A, I will count the links in link module A again. Here I am expecting the output to be the sum of the first two counts, however occasionally I get a result which is slightly less than the desired sum. When I have been able to trace this error down to a specific case, it was because some of the linksets in the new link module were empty and had moved over nothing at all, with no error message from my script. I just ran the script to move 6825 links into a LM with 4667 and got 11489 instead of 11492. I think that means an error in the script still exists, however maybe it is due to an odd anomaly of initially having the same link existing in both link modules. Let me know what you think, I have attached both the update script as well as the script I use to count the links in a Link Module.

I did also not see an error on your script right away - I think the way to go here, would be to dump all the links, before and after the move and find and compare the results to find out which links are missing.

I remember I have done a link dump script in some post, maybe that can help.

https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014846449&ps=25

 

(attachment_14846651_linkDump.zip)



It will allow you to quickly dump all links to a file and then read them back and count them (e.g. by link module) or dump them sorted to a file, so you will see where exactly you are missing links. You will probably have to modify the code here and there, but it might give you a quick start.

Maybe that helps, regards, Mathias

Re: Moving linksets script not working
llandale - Fri Aug 07 14:20:49 EDT 2015

JohnEarnshaw - Thu Aug 06 13:54:07 EDT 2015

I really appreciate the feedback, you made some great points and I took it all into consideration while updating my script. I especially like the idea of flushing deletions after removing the LMD just in case there was an obscure overlap. However even with the new and improved script I still ran into the same error as before. The problem I am getting with the script is that before the merge I will use a script to count all the links in Link Module A, as well as all of the links in Link Module B. After running the script to put the links from link module B into A, I will count the links in link module A again. Here I am expecting the output to be the sum of the first two counts, however occasionally I get a result which is slightly less than the desired sum. When I have been able to trace this error down to a specific case, it was because some of the linksets in the new link module were empty and had moved over nothing at all, with no error message from my script. I just ran the script to move 6825 links into a LM with 4667 and got 11489 instead of 11492. I think that means an error in the script still exists, however maybe it is due to an odd anomaly of initially having the same link existing in both link modules. Let me know what you think, I have attached both the update script as well as the script I use to count the links in a Link Module.

Lazy today, but I have a nagging memory that trying to create a link that already exists produces no link error:

  • o1 -> newlmName -> o2
  • string lasterror = lastError

That will be easy for you to check manually; write a 5 line DXL to create a link trapping the error, and then run it twice.  If you want your code to check you will need to look for the link in a link loop which I suspect will corrupt your outer for k ub i1 -> lmn do loop; in which case staging those links in a skip list will be required.  Alternatively, now that I think of it, you can loop through incoming links to o2.

I notice your count script turns filtering off whereas your copy link script does not.  Is it possible the default view has a Filter?  These are the cases that caused me to almost always use the "entire mod" loop and I'm guaranteed to get all the objects in the exact same order each time.  (BTW, your "filtering off" needs "current = sm" before it; just in case).

I notice your count script gets "all(o->lmn)" links but your copy script does not.

-Louie

Re: Moving linksets script not working
pommCannelle - Mon Aug 10 09:23:08 EDT 2015

( Seems that you are not dealing with the baselines ... If i'm not missing something, the posted code should ignore the links to baselines. 
When you are using the 'all' feature, perhaps you should use the targetVersion perm instead of the target one ... ;) )

Re: Moving linksets script not working
JSRowland - Wed Jan 11 15:11:20 EST 2017

I found this script really helpful. For my peace of mind, I hacked together John and Matthias' fine work into the attached, so that it would always be easy to verify that no links were lost in the process. I humbly submit it to posterity on the condition that I receive full credit for all errors and inelegant code. After running the script, a quick run of your favorite diff tool should verify that the only change is the link module name.

 

Note that in the course of testing, I was able to produce a corrupt module by, I believe, running the script with one of the source modules open in Shareable Edit. The result was an error message "Unable to parse treedata, Line 2, expected MaxID" or something similar. Simply re-running the script a couple of times to switch the linksets back and forth seems to have recovered the module. I lack the time or skill to fully investigate and fix the issue. I have since ensured that all modules are closed before running the tool and the issue has not recurred.


Attachments

Move Linksets.dxl

Re: Moving linksets script not working
RichRif - Fri Mar 23 10:29:43 EDT 2018

Mathias Mamsch - Fri Aug 07 11:10:21 EDT 2015

I did also not see an error on your script right away - I think the way to go here, would be to dump all the links, before and after the move and find and compare the results to find out which links are missing.

I remember I have done a link dump script in some post, maybe that can help.

https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014846449&ps=25

 

(attachment_14846651_linkDump.zip)



It will allow you to quickly dump all links to a file and then read them back and count them (e.g. by link module) or dump them sorted to a file, so you will see where exactly you are missing links. You will probably have to modify the code here and there, but it might give you a quick start.

Maybe that helps, regards, Mathias

Mathias,

I've downloaded the attachment_14846651_linkDump.zip file and when I try to open it I get an error saying the file is bad. Can you post the DXL file?

Regards, Rich

Re: Moving linksets script not working
Mathias Mamsch - Fri Mar 23 11:54:04 EDT 2018

RichRif - Fri Mar 23 10:29:43 EDT 2018

Mathias,

I've downloaded the attachment_14846651_linkDump.zip file and when I try to open it I get an error saying the file is bad. Can you post the DXL file?

Regards, Rich

I could download the file perfectly. I have attached the files separately. Hope it helps, regards, Mathias


Attachments

dumpLinksExample.dxl
linkStatistics.dxl